using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{
    /// <summary>
    /// Description: Concrete DataProvider for table CompanyInfo. Provides atomic API functions.
    /// Author:  phong.huynh
    /// Created: 13/08/2010 9:29:53 SA
    /// </summary>
    public class PRODUCT_TYPESDataAPI
    {
        private SQLHelper _dbTool = new SQLHelper();

        // ************************************
        // Implements function getByColumnName
        // ************************************

        public DataTable getByPROTYP_ID(System.Int32 PROTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID, PROTYP_ID) };
            return _dbTool.executeReader("SP_SEL_PRODUCT_TYPES_getByPROTYP_ID", parm);
        }

        //Get info type product with acc_id HUYNQ

        public DataTable getByACC_ID(System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("SP_SEL_PRODUCT_TYPES_getByACC_ID", parm);
        }

    
        public DataTable GetPRO_TYPE_NAME_ACCID( System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new  SqlParameter(PRODUCT_TYPESDTO._ACC_ID,  ACC_ID )};
            return _dbTool.executeReader("SP_SEL_PRODUCTS_GetPRO_TYPE_NAME", parm);
        }
        //-----------------------//////

        ////Get info type product with acc_id HUYNQ
        //public DataTable GetPRO_TYPE_NAME_ACCID( System.Int32 ACC_ID)
        //{
        //    SqlParameter[] parm = { new  SqlParameter(PRODUCT_TYPESDTO._ACC_ID,  ACC_ID )};
        //    return _dbTool.executeReader("SP_SEL_PRODUCTS_GetPRO_TYPE_NAME", parm);
        //}
        ////-----------------------//////


        public DataTable getByPROTYP_NAME(System.String PROTYP_NAME)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_NAME, PROTYP_NAME) };
            return _dbTool.executeReader("SP_SEL_PRODUCT_TYPES_getByPROTYP_NAME", parm);
        }
        // *************************************************
        // Implement function getAll/getByDynamicCondition
        // *************************************************


        public DataTable getAll(int acc_id)
        {
            SqlParameter[] parm = { new SqlParameter(ACCOUNTSDTO._ACC_ID, acc_id) };
            return _dbTool.executeReader("SP_SEL_PRODUCT_TYPES_getAll",parm);
        }
       

        // ********************************************************
        // Implement function getByPrimaryKeys / getByForeignKeys
        // In case table have composite primary/foreign keys
        // ********************************************************

        public DataTable getByPrimaryKeys(System.Int32 PROTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID, PROTYP_ID) };
            return _dbTool.executeReader("SP_SEL_PRODUCT_TYPES_getByPrimaryKeys", parm);
        }

        public DataTable getPRoByProID(System.Int32 ACC_ID,System.Int32 PROTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(ACCOUNTSDTO._ACC_ID, ACC_ID),
                                      new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID, PROTYP_ID), };
            return _dbTool.executeReader("SP_SEL_PRODUCT_BY_PRODUCTYPE_ID", parm);
        }

        public void insertPRODUCT_TYPES(System.Int32 ACC_ID, System.String PROTYP_NAME)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID,1),
                                    new SqlParameter(PRODUCT_TYPESDTO._ACC_ID,ACC_ID),
                                    new SqlParameter(PRODUCT_TYPESDTO._PROTYP_NAME,PROTYP_NAME)};
            int effectedRows = _dbTool.ExecuteNoneQuery("SP_INS_PRODUCT_TYPES_values", parm);

        }


        ///<summary>		
        /// Thu+.c hie^.n ca^u le^.nh update du+.a tre^n kho'a chi'nh
        ///</summary>

        //public bool updatePRODUCT_TYPES(System.Int32 PROTYP_ID, System.Int32 ACC_ID, System.String PROTYP_NAME)
        //{
        //    SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID,PROTYP_ID),
        //                            new SqlParameter(PRODUCT_TYPESDTO._ACC_ID,ACC_ID),
        //                            new SqlParameter(PRODUCT_TYPESDTO._PROTYP_NAME,PROTYP_NAME)};
        //    int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_PRODUCT_TYPES_update", parm);

        //    return affectRows == 1;
        //}
        ///// <summary>
        /// /////////////////////////
        /// </summary>
        /// <param name="PROTYP_ID"></param>
        /// <param name="PROTYP_NAME"></param>
        /// <returns></returns>
        public int updatePRODUCT_TYPES(System.Int32 PROTYP_ID, System.String PROTYP_NAME,System.Int32 ACC_ID)
        {
<<<<<<< .mine
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID,PROTYP_ID),
                                    
                                    new SqlParameter(PRODUCT_TYPESDTO._PROTYP_NAME,PROTYP_NAME),
                                   new SqlParameter(PRODUCT_TYPESDTO._ACC_ID,ACC_ID)};
=======
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID,PROTYP_ID),                                    
                                    new SqlParameter(PRODUCT_TYPESDTO._PROTYP_NAME,PROTYP_NAME),
                                  new SqlParameter(PRODUCT_TYPESDTO._ACC_ID,ACC_ID)};
>>>>>>> .r340
            int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_PRODUCT_TYPES_Updated", parm);
            return affectRows = 1;

            
        }
        // ********************************************************************************
        // Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
        // ********************************************************************************

        // return number of deleted rows		
        public int deleteAll()
        {
            return _dbTool.ExecuteNoneQuery("SP_DEL_PRODUCT_TYPES_deleteAll");
        }

        // return number of deleted rows
        public int deleteByPrimaryKeys(System.Int32 PROTYP_ID)
        {
            SqlParameter[] parm = { new SqlParameter(PRODUCT_TYPESDTO._PROTYP_ID, PROTYP_ID) };
            return _dbTool.ExecuteNoneQuery("SP_DEL_PRODUCT_TYPES_deleteByPrimaryKeys", parm);
        }

    }
}